<template>
    {{state}}
</template>

<script>
import {ref, watch} from 'vue'
export default {
    setup() { 
        const state = ref(0)

        watch(state, (newValue, oldValue) => {
          console.log(`原值为${oldValue}`)
          console.log(`新值为${newValue}`)
          /* 1秒后打印结果：
                  原值为0
                  新值为1
          */
        })
        
        // 1秒后将state值+1
        setTimeout(() => {
          state.value ++
        }, 1000)
        return{
            state
        }
    }
}
</script>
